import { useStoreState } from "@hooks/index"
import { timeExpired } from '@util/index'
import { Navigate } from "react-router-dom"

export default function Protect(Component: React.ComponentType) {
  const ProtectComponent: React.FC = function (props: {}) {
    const { token } = useStoreState("token")
    if (timeExpired(token)) {
      // token 过期
      return <Navigate to="/login" />
    }
    return (
      <Component />
    )
  }
  ProtectComponent.displayName = Component.name
  return ProtectComponent
}
